//
//  NovaBarChartView.swift
//  Demo
//
//  Created by 李然 on 2023/3/6.
//

import UIKit

open class NovaBarChartView: NovaBaseChartView {
    
    public var showPlaceBar = false
    public var placeBarColor: UIColor = .clear
    
    open override func draw(_ rect: CGRect) {
        super.draw(rect)
        
        drawPlaceBar(rect)
    }
    
    open func drawPlaceBar(_ rect: CGRect) {
        let xCount = self.data.count
        guard xCount > 0 else { return }
        
        guard let context = UIGraphicsGetCurrentContext() else { return }
        
        context.saveGState()
        defer { context.restoreGState() }
        
        for index in 0..<self.data.count {

            guard self.barRects.count > index else {
                return
            }
            let barRect = self.barRects[index]
            
            if showPlaceBar {
                context.setFillColor(placeBarColor.cgColor)
                let cornerRadii = CGSize(width: barCornerRadius, height: barCornerRadius)
                let path = UIBezierPath.init(roundedRect: barRect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: cornerRadii)
                path.fill()
            }
        }
    }
}
